#include <QtSql>

using namespace std;

void setup() {
  QSettings settings;
  
  settings.setValue("hotkeyMod", Qt::CTRL);
  settings.setValue("hotkey", Qt::Key_Space);
  
  // Configure directory paths
  #ifdef _WIN32
  settings.setValue("dbPath", QDir::homePath()+"/Application Data/ki/kiDB");
  settings.setValue("favDir", QDir::homePath()+QString::fromStdString("/ki/fav"));
  settings.setValue("verbsDir", QDir::homePath()+QString::fromStdString("/ki/verbs"));
  #else
  settings.setValue("dbPath", QDir::homePath()+"/Library/Application Support/ki/kiDB");
  settings.setValue("favDir", QDir::homePath()+QString::fromStdString("/ki/fav"));
  settings.setValue("verbsDir", QDir::homePath()+QString::fromStdString("/ki/verbs"));
  #endif
  {
    // Set up database
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "setup");
    db.setDatabaseName(settings.value("dbPath").toString());
    
    if (!db.open()) {
      qDebug()<<"Database could not be opened";
    }
    
    QSqlQuery sqlQ(db);
    sqlQ.exec("CREATE TABLE nHistory (path TEXT PRIMARY KEY, lastCall INT DEFAULT (strftime('%s','now')), freq INT DEFAULT 1, keyword TEXT)");
    sqlQ.exec("CREATE TABLE vHistory (path TEXT PRIMARY KEY, lastCall INT DEFAULT (strftime('%s','now')), freq INT DEFAULT 1, keyword TEXT)");
    sqlQ.exec("CREATE TABLE aHistory (path TEXT PRIMARY KEY, lastCall INT DEFAULT (strftime('%s','now')), freq INT DEFAULT 1, keyword TEXT)");
  }
  QSqlDatabase::removeDatabase("setup");
  
  // Set scoring constants
  settings.setValue("begHigh", 50);
  settings.setValue("midBonus", 20);
  settings.setValue("endHigh", 20);
  settings.setValue("fragPen", 7); // less frags better than long len, max frag = indices.size()-1
  settings.setValue("freqBonus", 10);
  settings.setValue("recencyHigh", 50);
}
